using System;
using System.Diagnostics.Contracts;
using MongoDB.Driver;

namespace Charisma.MongoDb.Linq
{
  internal class TranslatedQuery<TResult>
  {
    private readonly Func<MongoCollection, TResult> materializer;

    public TResult Execute(MongoCollection collection)
    {
      return materializer.Invoke(collection);
    }

    [ContractInvariantMethod]
    private void ObjectInvariant()
    {
      Contract.Invariant(materializer != null);
    }

    public TranslatedQuery(Func<MongoCollection, TResult> materializer)
    {
      Contract.Requires(materializer != null);
      Contract.Ensures(this.materializer!=null);

      this.materializer = materializer;
    }
  }
}